package forum.server.controller;

import forum.server.domain.Post;
import forum.server.exceptions.InvalidSearchRangeException;
import forum.server.exceptions.NoSuchUserException;

public interface SearchEngine {
	
	/**
	 * Adds the post p to the search engine.
	 * Fields that should be indexed:<br>
	 *  1. Each word in the content of the post.<br>
	 *  2. The username of the author who wrote the post.<br>
	 * @param p The post which we want to add to the indexing data base of the search engine.
	 */
	public void addData(Post p);
	
	/**
	 * Removes any indexed data on the post 'p' from the database.
	 * @param p the post which all of it's data will be erased from the indexing.
	 */
	public void removeData(Post p);
	
	/**
	 * Search for all the posts (SearchHit) written by the author called username.<br><br>
	 * 	 
	 * Example: <i>searchByAuthor("Jonny82",0,10)</i> will return the first ten hits(posts) written
	 * by the author/user Jonny82. 
	 * 
	 * @param username The username of the author who wrote the post.
	 * @param from hits from index from
	 * @param to hits until index to
	 * 
	 * @return The search hits from index from till index to - 1
	 * @throws NoSuchUserException 
	 * @throws InvalidSearchRangeException 
	 */
	public SearchHit[] searchByAuthor(String username, int from, int to) throws NoSuchUserException, InvalidSearchRangeException;
	
	/**
	 * Search for all the posts(SearchHit) which contain the phrase.<br><br>
	 * 	 
	 * Examples:<br><br>
	 * <i>searchByContent(\""read my lips"\",10,20)</i> will search for the exact phrase read my lips and return hits 10-19.<br><br>
	 * <i>searchByContent("apples OR bananas",5,10)</i> will search for posts who contain either apples, bananas <b>or</b> both and return hits 5-10.<br><br>
	 * <i>searchByContent("oranges AND apples",0,10)</i> will search for posts who must contain both oranges <b>and</b> apples and return hits 0-9.<br><br>
	 * 
	 * 
	 * @param phrase The phrase which we would like to search
	 * @param from hits from index from
	 * @param to hits until index to
	 * @return The search hits from index from till index to - 1
	 * @throws InvalidSearchRangeException 
	 */
	public SearchHit[] searchByContent(String phrase, int from, int to) throws InvalidSearchRangeException;

	
}
